package fc.sj.study.utils;

import android.util.Log;

/**
 * Created by Joshua on 2017/4/6 0006.
 */

public class LogUtil {
    //测试版本开启log日志,上线则关闭,防止信息泄露
    public static boolean Debug=true;
    public LogUtil(){
        throw new UnsupportedOperationException("不允许该操作");
    }
    private static String logLine(StackTraceElement caller){
        String a=caller.getClassName();
        String b=caller.getMethodName();
        int c=caller.getLineNumber();
        return a+" "+b+" "+c;
    }
    //错误日志
    public static void e(String title,String message){
        if(Debug){
            StackTraceElement caller = getCallerStackTraceElement();
            String Tag=logLine(caller);
            Log.e(title+Tag,message);
        }
    }
    public static void i(String title,String message){
        if(Debug){
            StackTraceElement caller = getCallerStackTraceElement();
            String Tag=logLine(caller);
            Log.i(title+Tag,message);
        }
    }
    //debug测试日志
    public static void d(String title,String message){
        if(Debug){
            StackTraceElement caller = getCallerStackTraceElement();
            String Tag=logLine(caller);
            Log.d(title+Tag,message);
        }
    }
    private static StackTraceElement getCallerStackTraceElement(){
        //暂时不知原因,选第四个就对了
        return Thread.currentThread().getStackTrace()[4];
    }
}
